package com.example.demo.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 
 * <p>
 * 功能描述： 邮件发送工具类
 * </p>
 * 
 * @author lixh
 * @date 2019年1月7日 上午10:32:37
 * @company chinobot
 * @version 1.0
 */
@RestController
@SpringBootApplication
public class SendEmail {

	@Autowired
	private JavaMailSender javaMailSender;

	/**
	 * 
	 * 方法描述:
	 * 
	 * @param receiveId
	 *            接收方账号
	 * @return
	 * @author lixh
	 */
	@RequestMapping("/sendMessage")
	@ResponseBody
	public String sendMessage(@RequestParam("receiveId") String receiveId) {
		SimpleMailMessage message = new SimpleMailMessage();
		message.setFrom("3295558232@qq.com");
		if (StringUtils.isEmpty(receiveId)) {
			return "请输入接收方账号";
		}
		message.setTo(receiveId);
		message.setSubject("测试邮件");
		message.setText("世界上第x封邮件");
		javaMailSender.send(message);
		return "发送成功";
	}
}
